package com.ruoyi.operation.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.operation.domain.StudentInfo;
import com.ruoyi.operation.mapper.StudentInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.operation.mapper.OrderInfoMapper;
import com.ruoyi.operation.domain.OrderInfo;
import com.ruoyi.operation.service.IOrderInfoService;

/**
 * 订单信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-07
 */
@Service
public class OrderInfoServiceImpl implements IOrderInfoService 
{
    @Autowired
    private OrderInfoMapper orderInfoMapper;
    @Autowired
    private StudentInfoMapper studentInfoMapper;
    /**
     * 查询订单信息
     * 
     * @param id 订单信息主键
     * @return 订单信息
     */
    @Override
    public OrderInfo selectOrderInfoById(Long id)
    {
        return orderInfoMapper.selectOrderInfoById(id);
    }

    /**
     * 查询订单信息列表
     * 
     * @param orderInfo 订单信息
     * @return 订单信息
     */
    @Override
    public List<OrderInfo> selectOrderInfoList(OrderInfo orderInfo)
    {
        //非管理员只能查自己的
        if (!SecurityUtils.hasRole("1")) {
            orderInfo.setYhid(SecurityUtils.getUserId());
        }
        return orderInfoMapper.selectOrderInfoList(orderInfo);
    }

    /**
     * 新增订单信息
     * 
     * @param orderInfo 订单信息
     * @return 结果
     */
    @Override
    public int insertOrderInfo(OrderInfo orderInfo)
    {
        orderInfo.setCjsj(new Date());
        orderInfo.setDdh(IdUtils.fastSimpleUUID());
        orderInfo.setDdzt("下单成功");
        orderInfo.setYhid(SecurityUtils.getUserId());
        orderInfo.setYhmc(SecurityUtils.getUsername());
        orderInfoMapper.insertOrderInfo(orderInfo);
        StudentInfo studentInfo = new StudentInfo();
        studentInfo.setCjsj(new Date());
        studentInfo.setZh(orderInfo.getZhmc());
        studentInfo.setMm(orderInfo.getZhmm());
        studentInfo.setXx(orderInfo.getXxmc());
        studentInfo.setKczt("0");
        studentInfo.setZtxx("排队中");
        studentInfo.setKcfw(orderInfo.getSpmc());
        studentInfo.setDdh(orderInfo.getDdh());
        studentInfo.setYhid(orderInfo.getYhid());
        studentInfo.setYhmc(orderInfo.getYhmc());
        int i = studentInfoMapper.insertStudentInfo(studentInfo);
        return i;
    }

    /**
     * 修改订单信息
     * 
     * @param orderInfo 订单信息
     * @return 结果
     */
    @Override
    public int updateOrderInfo(OrderInfo orderInfo)
    {
        return orderInfoMapper.updateOrderInfo(orderInfo);
    }

    /**
     * 批量删除订单信息
     * 
     * @param ids 需要删除的订单信息主键
     * @return 结果
     */
    @Override
    public int deleteOrderInfoByIds(Long[] ids)
    {
        return orderInfoMapper.deleteOrderInfoByIds(ids);
    }

    /**
     * 删除订单信息信息
     * 
     * @param id 订单信息主键
     * @return 结果
     */
    @Override
    public int deleteOrderInfoById(Long id)
    {
        return orderInfoMapper.deleteOrderInfoById(id);
    }

    @Override
    public int saveOrder(Map map) {
        return 0;
    }
}
